n = int(input())
mx = 0
flag = True

def check(n):
    
    l1 = list()
    n2 = str(n)

    l1.append(int(n2))
    l1.append(int(n2[:3]))
    l1.append(int(n2[1:]))
    l1.append(int(n2[:2]))
    l1.append(int(n2[1:3]))
    l1.append(int(n2[2:]))
    l1.append(int(n2[:1]))
    l1.append(int(n2[1:2]))
    l1.append(int(n2[2:3]))
    l1.append(int(n2[3:]))

    return l1

if 999 < n < 10000:
    
    l = check(n)
    
    for i in range(len(l)):
        
        for j in range(2, l[i]//2):
            
            if l[i] % j == 0:
                flag = False
            
        if flag != False:
            if mx < l[i]:
                mx = l[i]
        flag = True
        
    print(mx)
    
else:
    
    print(0)
